package floappcontest.core.beans;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import floappcontest.core.beans.interfaces.PersistentObject;

/**
 * @author ricardo
 *
 */
@Entity
@Table( name= "team")
public class Team implements PersistentObject{

	private String name;
	private Tutor tutor;
	private Integer numberOfStudents;
	
    /**
     * Default empty constructor
     */
    public Team(){
    	// Default empty constructor    	
    }
	
	/**
	 * @param name
	 * @param tutor
	 * @param numberOfStudents
	 */
	public Team(String name, String tutor, Integer numberOfStudents){
		setName( name );
//		setTutor( tutor );
		setNumberOfStudents( numberOfStudents );
	}
	
	/**
	 * @param atb
	 * @param newValue
	 */
	public void setProperty(String atb, String newValue){
		try {
			Team.class.getDeclaredField(atb).set(this, newValue);
		} catch (Exception e) {
			// TODO Auto-generated catch block
		}
	}
	
	public String getProperty(String property){
		String value = null;
		try {
			value = this.getClass().getDeclaredField( property ).get( this ).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
		}
		return value;
	}
	
	/**
	 * @return
	 */
	@Id 
	@Column(name="name", length=200, nullable=false)
	public String getName() {
		return this.name;
	}

	/**
	 * @return
	 */
	@ManyToOne
	public Tutor getTutor() {
		return this.tutor;
	}
	
	@Column(name="number_of_students", nullable=false)
	public Integer getNumberOfStudents() {
		return this.numberOfStudents;
	}
	
	/**
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * @param tutor
	 */
	public void setTutor(Tutor tutor) {
		this.tutor = tutor;
	}
	
	/**
	 * @param numberOfStudents
	 */
	public void setNumberOfStudents(Integer numberOfStudents) {
		this.numberOfStudents = numberOfStudents;
	}
	
	public String toString(){
		return getName();
	}
}